package com.wcfsy.wechat.wx.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.wcfsy.wechat.wx.entity.PrizeInfo;
import com.wcfsy.wechat.wx.pagination.IPage;
import com.wcfsy.wechat.wx.pagination.impl.Page;
import com.wcfsy.wechat.wx.service.IActivityInfoService;
import com.wcfsy.wechat.wx.service.IPrizeInfoService;
import com.wcfsy.wechat.wx.sys.dao.PrizeInfoDao;

@Service("prizeInfoService")
public class PrizeInfoServiceImpl implements IPrizeInfoService {
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	@Resource
	private IActivityInfoService activityInfoService;
	@Resource
	private PrizeInfoDao prizeInfoDao;

	@Override
	public PrizeInfo getPrizeInfoById(int prizeId) {
		return prizeInfoDao.getById(prizeId);
	}

	@Override
	public List<PrizeInfo> findPrizeInfoList() {
		Map<String, Object> paramMap = new java.util.HashMap<String, Object>();
		/*
		 * map.put("multipleStates", new int[] {
		 * PrizeInfoConstant.PrizeStatusConstant.PRIZE_INFO_STATUS_2,
		 * PrizeInfoConstant.PrizeStatusConstant.PRIZE_INFO_STATUS_3 });
		 * ActivityInfo wechatActivity = activityInfoService
		 * .getActivityByCode(PrizeInfoConstant.WXSMHD); if (wechatActivity ==
		 * null) { return null; } // 查询参与活动的奖品Id集合 List<String> productIds = new
		 * ArrayList<String>(); if (wechatActivity != null) { String[]
		 * productArray = wechatActivity.getProductIds().split(","); for (int i
		 * = 0; i < productArray.length; i++) { if
		 * (StringUtils.isNotBlank(productArray[i])) {
		 * productIds.add(productArray[i]); } } } map.put("productIds",
		 * productIds);
		 */
		return prizeInfoDao.findByParam(paramMap);
	}

	@Override
	public IPage<PrizeInfo> queryPrizeInfoByPage(Map<String, Object> paramMap,
			int index, int size) {
		paramMap.put("index", index);
		paramMap.put("size", size);
		paramMap.put("limit", "limit");
		return new Page<PrizeInfo>(prizeInfoDao.findByParam(paramMap),
				prizeInfoDao.count(paramMap), index, size);
	}

	@Override
	public List<PrizeInfo> getAllPrizeInfo(int[] prizeIds) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		if (prizeIds != null && prizeIds.length > 0) {
			paramMap.put("prizeIds", prizeIds);
		}
		return prizeInfoDao.findByParam(paramMap);
	}

	@Override
	public int addPrizeInfo(PrizeInfo info) {
		long rlt;
		try {
			rlt = prizeInfoDao.add(info);
			return (int) rlt;
		} catch (Exception e) {
			logger.info("添加奖品出现异常", e);
			return -1;
		}
	}

	@Override
	public int updatePrizeinfo(PrizeInfo info) {
		try {
			return prizeInfoDao.update(info);
		} catch (Exception e) {
			logger.info("修改奖品出现异常", e);
			return -1;
		}
	}

	@Override
	public void deleteById(int id) throws Exception {
		prizeInfoDao.deleteById(id);
	}

}
